package com.hspedu.api_;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author DL5O
 * @version 1.0
 */
public class API_Exercise {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress localHost = InetAddress.getLocalHost();//获取本地地址
        System.out.println("localHost:" + localHost);
        String hostName = localHost.getHostName();
        System.out.println("本地主机名:" + hostName);
        String hostAddress = localHost.getHostAddress();
        System.out.println("本地ip地址:" + hostAddress);


        //通过主机名/域名获取id地址和主机名
        InetAddress ip = InetAddress.getByName(hostName);
        System.out.println("通过getByName获取的ip地址:" + ip.getHostAddress());

        InetAddress baiduIP = InetAddress.getByName("www.baidu.com");
        System.out.println("百度域名和ip信息" + baiduIP);

        String baiduHostName = baiduIP.getHostName();
        System.out.println("百度域名:" + baiduHostName);

    }
}
